from django_redis import get_redis_connection

class MyRedis:
    def __init__(self):
        self.redis = get_redis_connection("code")
    # 设置key，时间是20min
    def setstr(self,key,value,time):
        return self.redis.setex(key,time,value)
    def getstr(self,key):
        val =  self.redis.get(key)
        if val:
            return val.decode("utf-8")
        else:
            return None
# 设置一个参数key 带增量
    def hotadd(self,key,word):
        return self.redis.zincrby(key,1,word)
    def hotget(self,key,num):
        return self.redis.zrevrange(key,0,-1)
    # 存储普通字符串
    def setstrno(self,key,value):
        return self.redis.set(key,value)
    # 删除指定的key
    def delstr(self,key):
        return self.redis.delete(key)


redistoll = MyRedis()